from time import sleep
from concurrent.futures import ThreadPoolExecutor

from threading import Lock

class Account():
    def __init__(self) -> None:
     self._balance=0
     self._lock = Lock()
    
    def deposit(self,money):
        with self._lock:
            new_balance = self._balance+money
            #其他业务逻辑
            sleep(0.01)
            self._balance = new_balance
    
    @property
    def balance(self):
        return self._balance
    

def main():
    account = Account()
    pool = ThreadPoolExecutor(max_workers=20)
    
    for _ in range(100):
        pool.submit(account.deposit,1)
    pool.shutdown()
    
    print(account.balance)
    
if __name__ == "__main__":
    main()
